home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 2 / L'Effet Pommier - Volume 02.iso / Echecs / GNU Chess Pro / GNU Chess Docs / GNU⁄alogorithm < prev    next >
Text File  |  1993-10-05  |  2KB  |  52 lines

  1.                                                                                         New Move Generation Algorithm:
  2.                                                                                                         Revision: 1989-09-06
  3.                                                                                             Author: Hans Eric Sandstroem.
  4.  
  5. This algorithm is the result of an attempt to make an hardware move generator, but since I newer had the time and resources to build the hardware I wrote a software version and incorporated that one into gnuchess. This was the best way I could think of sharing this algorithm with the computer chess community.
  6.  
  7. If there is anybody out there with the time and resources to build a hardware move generator I will be glad to assist.
  8.  
  9. The general idea behind this algorithm is to pre calculate a lot of data. The data that is pre calculated is every possible move for every piece from every square disregarding any other pieces on the board. This pre calculated data is stored in an array that looks like this:
  10.  
  11. struct sqdata {
  12.   short nextpos;
  13.   short nextdir;
  14. };
  15. struct sqdata posdata[8][64][64];
  16. /* posdata[piecetype][fromsquare][destinationsquare] */
  17. example:
  18.     the first move for a queen at e8 is stored at;
  19.     posdata[queen][e8][e8].nextpos
  20.     suppose this is e7 and e7 is occupied then the next move
  21.     will be found in;
  22.     posdata[queen][e8][e7].nextdir
  23.  
  24. To handle the differeces between white and black pawns (they move in opposite directions) an array ptype has been introduced:
  25.  
  26. static const short ptype[2][8] = {
  27.   no_piece,pawn,knight,bishop,rook,queen,king,no_piece,
  28.   no_piece,bpawn,knight,bishop,rook,queen,king,no_piece};
  29.            ^^^^^
  30. And it is used like this:
  31.    piecetype = ptype[side][piece]
  32.  
  33. When generating moves for pieces that are not black pawns, piece can be used directly in posdata. As in the example above.
  34.  
  35. Thus the only thing one has to do when generating the moves is to check for collisions with other pieces.  the move generation to do this looks like this: (for non pawns)
  36.     p = posdata[piece][sq];
  37.     u = p[sq].nextpos;
  38.     do {
  39.       if (color[u] == neutral) {
  40.     LinkMove(ply,sq,u,xside);
  41.     u = p[u].nextpos;
  42.       }
  43.       else {
  44.     if (color[u] == xside) LinkMove(ply,sq,u,xside);
  45.     u = p[u].nextdir;
  46.       }
  47.     } while (u != sq);
  48.  
  49.  - I`nt this just beautiful!
  50.  
  51. The array posdata is initialized in the routine Initialize_moves. This routine is called just once and it works so no time has been spent on the structure of this code. GenMoves and CaptureList generates the moves but the routines ataks, BRscan, Sqatakd, KingScan and trapped also relies on the move generation algoritm so they have also been rewritten.
  52.